package com.example.teach.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.teach.entity.Article;
import com.example.teach.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface ArticleMapper extends BaseMapper<Article> {

    @Update("update article set view_count=view_count+1 where id=#{id}")
    void add(Integer id);

    @Update("update article set like_count=like_count+1 where id=#{id}")
    void addLike(Integer articleId);

    @Update("update article set like_count=like_count-1 where id=#{id}")
    void subtractLike(Integer articleId);

    @Select("select * from article where user_id=#{userId}")
    Article selectByUserId(Integer userId);

    @Update("update article set comment_count=comment_count+1 where id=#{articleId}")
    void addComment(Integer articleId);

    @Update("update article set comment_count=comment_count-1 where id=#{articleId}")
    void subComment(Integer articleId);


}
